#include <iostream>
#include <string>
#include <algorithm>

std::string Transfer2Base(int num, int B) {
    std::string digits;

    while (num) {
        int digit = num % B;
        digits += (digit < 10) ? ('0' + digit) : ('A' + digit - 10);
        num /= B;
    }

    if (digits.empty()) {
        digits = "0";
    }

    std::reverse(digits.begin(), digits.end());

    return digits;
}

/**
 * 平方回文数
 */
int main() {
    int B;
    std::cin >> B;

    for (int i = 1; i <= 300; i++) {
        int square = i * i;
        std::string squareStr = Transfer2Base(square, B);
        std::string reversed = squareStr;
        std::reverse(reversed.begin(), reversed.end());
        if (squareStr == reversed) {
            std::cout << Transfer2Base(i, B) << " " << squareStr << "\n";
        }
    }

    return 0;
}
